Repository navigation
Conversation
Port of the AdjointReplication C++ example (the static replication of a down-and-out barrier option with European options from Joshi, The Concepts and Practice of Mathematical Finance, ch. 17). The replicating portfolio is built on the tape - the notionals that kill the portfolio value on the barrier are computed from recorded portfolio values - so a single adjoint pass gives the sensitivities of the portfolio value to the zero rates, the strike, the volatility, the underlying, and the barrier level. The example prints the reference barrier option value (4.652838435318750) next to the replicating portfolio value (4.154324163665421) and cross-checks every adjoint against bump-and-reprice finite differences. One deliberate difference from the C++ code: it registers a single variable for the flat 4% rate shared by all curve nodes, while this port registers one input per node (all 4%) and reports the rhos per node.
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20.
Python port of the
AdjointReplicationC++ example (Joshi's static replication of a down-and-out barrier option with European options), following the pattern ofswap-adjoint.py:Testing: the current
QuantLibAADwheel is not reachable from my sandbox, so I ran the identical example code against QuantLib-Risks 1.33.3 (the direct predecessor of QuantLibAAD; only the tape-construction lines and one payoff-width argument differ between the two APIs). It runs end to end: barrier option value 4.652838435318750, replicating portfolio 4.154324163665421, and all adjoints match bumping to within 2.1e-4 relative (worst case: vega, adjoint -7.045801 vs bump -7.047242; most are at 1e-5 or better).One deliberate difference from the C++ code, also noted in the example: the C++ registers a single variable for the flat 4% rate shared by all nine curve nodes, so its rho is the sum over nodes. This port registers one input per node (all set to 4%) and reports the rhos per node; the per-node values sum to the C++-style sensitivity. Shout if you would prefer the single-variable form instead.
Note: this repo requires a signed CLA before merge (per CONTRIBUTING) — I understand it will be handled through the CLA flow.